'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

' Interaction logic for SignInPage.xaml
Partial Public Class SignInPage
    Inherits System.Windows.Controls.Page

    Private _viewModel As SignInPageViewModel

    Public ReadOnly Property ViewModel() As SignInPageViewModel
        Get
            Return _viewModel
        End Get
    End Property

    Public Sub New()
        _viewModel = New SignInPageViewModel

        InitializeComponent()
    End Sub

    Private Sub OnIdentityDoubleClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim identity As IdentityManager.IIdentity

        Try
            identity = DirectCast(ViewModel.Identities.CurrentItem, IdentityManager.IIdentity)

            ' Check whether there is an identity selected.
            If identity Is Nothing Then Return

            ViewModel.SignIn(identity)

            App.ShowStatusWindows()
        Catch ex As Exception
            Core.Kernel.Exceptions.PublishException(ex)
        End Try
    End Sub

    Private Sub OnSignInClick(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim identity As IdentityManager.IIdentity

        Try
            identity = DirectCast(ViewModel.Identities.CurrentItem, IdentityManager.IIdentity)

            ' Check whether there is an identity selected.
            If identity Is Nothing Then Return

            ViewModel.SignIn(identity)

            App.ShowStatusWindows()
        Catch ex As Exception
            Core.Kernel.Exceptions.PublishException(ex)
        End Try
    End Sub

    Private Sub OnAddNewClick(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
        Try
            ViewModel.NavigateToCreateIdentityPage()
        Catch ex As Exception
            Core.Kernel.Exceptions.PublishException(ex)
        End Try
    End Sub

    Private Sub OnEditClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim identity As IdentityManager.IIdentity

        Try
            identity = DirectCast(ViewModel.Identities.CurrentItem, IdentityManager.IIdentity)

            ' Check whether there is an identity selected.
            If identity Is Nothing Then Return

            ViewModel.NavigateToEditIdentityPage(identity)
        Catch ex As Exception
            Core.Kernel.Exceptions.PublishException(ex)
        End Try
    End Sub
End Class
